import { createStore } from 'vuex'
import { reqSaleDetials, reqNewDetials, reqCar, reqOrder } from '@/api/allMsg'
export default createStore({
  state: {
    goodsInfo: {}, // 首页热售商品列表
    goodsNewInfo: {} // 首页新款商品列表
  },

  mutations: {
    goodsInfo (state, data) {
      state.goodsInfo = data
    },
    goodsNewInfo (state, data) {
      state.goodsNewInfo = data
    }
  },

  actions: {
    async goodsInfo ({ commit }, data) {
      const result = await reqSaleDetials(data) // 调用函数reqSaleDetials并返回数据结果
      console.log(result, '0000')
      if (result.code == 200) {
        commit('goodsInfo', result.data)
      }
    },

    async goodsNewInfo ({ commit }, data) {
      const result = await reqNewDetials(data)
      // console.log(result);
      if (result.code == 200) {
        commit('goodsNewInfo', result.data)
      }
    }
  },
  getters: {
    goodList (state) {
      return state.goodsInfo.list || []
    },
    goodListAll (state) {
      return state.goodsNewInfo.list || []
    }
  }
})
